<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<title>1.2 卷积计算 | pansis.io</title>
<link rel="shortcut icon" href="https://github.pansis.site/favicon.ico">
<link href="https://github.pansis.site/styles/main.css" rel="stylesheet">
<link href="//at.alicdn.com/t/c/font_1678829_b85ccgkdqkr.css" rel="stylesheet">
<link href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css" rel="stylesheet">
<link rel="alternate" type="application/rss+xml" title="pansis.io » Feed" href="https://github.pansis.site/atom.xml">
        <meta name="description" content="一、卷积的矩阵转换
1、各参数表示

N batch_size
M  输出通道数
C  输入通道数
H/W  输入图长宽
R/S   卷积核长宽
E/F   输出图长宽
U       卷积步长

2、卷积运算公式

多通道输入，多通道输出..." />
        <meta name="keywords" content="飞行器智能处理器设计实验" />
        <!-- OG -->
        <meta property="og:locale" content="zh_CN">
        <meta property="og:title" content="1.2 卷积计算" />
        <meta property="og:type" content="article" />
        <meta property="og:description" content="一、卷积的矩阵转换
1、各参数表示

N batch_size
M  输出通道数
C  输入通道数
H/W  输入图长宽
R/S   卷积核长宽
E/F   输出图长宽
U       卷积步长

2、卷积运算公式

多通道输入，多通道输出...">
        <meta property="og:url" content="https://github.pansis.site/post/1.2 卷积计算/" />
        <meta property="og:site_name" content="pansis.io">
        <meta property="og:updated_time" content="2024-03-11">
        <meta property="og:image" content="" />
        <meta property="og:image:secure_url" content="">
        <meta property="og:image:alt" content="1.2 卷积计算">
        <!-- Twitter (post.ejs) -->
        <meta name="twitter:card" content="summary_large_image">
        <meta name="twitter:title" content="1.2 卷积计算">
        <meta name="twitter:description" content="一、卷积的矩阵转换
1、各参数表示

N batch_size
M  输出通道数
C  输入通道数
H/W  输入图长宽
R/S   卷积核长宽
E/F   输出图长宽
U       卷积步长

2、卷积运算公式

多通道输入，多通道输出...">
        <!-- <meta name="twitter:site" content="@WBoy0609">
        <meta name="twitter:creator" content="@WBoy0609"> -->
        <meta name="twitter:image" content="">
</head>

<body>
    <div class="main animated">
        <div class="header animated fadeInDown">
    <div class="site_title_container">
        <div class="site_title">
            <a href="https://github.pansis.site">pansis.io</a>
        </div>
    </div>
    <div class="my_socials">
        
            
        
            
        
            
        
            
        
            
        
            
        
            
        
        <a href="https://github.pansis.site/atom.xml" title="rss" target="_blank"><i class="iconfont icon-rss"></i></a>
    </div>
</div>

    <div class="header_menu">
        
            
                <a href="/" class="menu">首页</a>
            
        
            
                <a href="/tag/GWAaV2nvk/" class="menu">程序设计课程</a>
            
        
            
                <a href="/tag/24hangc" class="menu">比赛</a>
            
        
            
                <a href="/tag/L7r9STb75/" class="menu">Python教程</a>
            
        
            
                <a href="/tags" class="menu">分类</a>
            
        
        <div class="gridea-search-div">
            <form id="gridea-search-form" action="https://github.pansis.site/search/">
                <input class="gridea-search-input" autocomplete="off" spellcheck="false" name="q"/>
            </form>
        </div>
    </div>

            <div class="autopagerize_page_element">
                <div class="content">
                    <div class="post_page">
                        <div class="post animated fadeInDown">
                            <div class="post_title post_detail_title">
                                <h2>
                                    1.2 卷积计算
                                </h2>
                                <span class="article-info">
                                    2024-03-11, 383 words, 2 min read
                                </span>
                            </div>
                            <div class="post_content markdown">
                                <p class="md_block">
                                    <span class="md_line md_line_start md_line_end">
                                        <h2 id="一-卷积的矩阵转换">一、卷积的矩阵转换</h2>
<h4 id="1-各参数表示">1、各参数表示</h4>
<ul>
<li>N batch_size</li>
<li>M  输出通道数</li>
<li>C  输入通道数</li>
<li>H/W  输入图长宽</li>
<li>R/S   卷积核长宽</li>
<li>E/F   输出图长宽</li>
<li>U       卷积步长</li>
</ul>
<h4 id="2-卷积运算公式">2、卷积运算公式</h4>
<figure data-type="image" tabindex="1"><img src="http://cos.pansis.site/202403112056031.png/abc123" alt="image-20240311205631969" loading="lazy"></figure>
<p>多通道输入，多通道输出</p>
<figure data-type="image" tabindex="2"><img src="http://cos.pansis.site/202403112053137.png/abc123" alt="image-20240311205232665" loading="lazy"></figure>
<figure data-type="image" tabindex="3"><img src="http://cos.pansis.site/202403112053151.png/abc123" alt="image-20240311205238918" loading="lazy"></figure>
<h4 id="3-转换后的各矩阵大小和数据冗余倍数">3、转换后的各矩阵大小和数据冗余倍数</h4>
<figure data-type="image" tabindex="4"><img src="http://cos.pansis.site/202403112058377.png/abc123" alt="image-20240311205850287" loading="lazy"></figure>
<h4 id="4-关键优化途径">4、关键优化途径</h4>
<p>减少数据搬运 、减少乘法次数</p>
<h2 id="二-减少乘法次数">二、减少乘法次数</h2>
<h4 id="1-算法">1、算法</h4>
<p>Winograd算法</p>
<h4 id="2-一维卷积">2、一维卷积</h4>
<figure data-type="image" tabindex="5"><img src="http://cos.pansis.site/202403112102144.png/abc123" alt="image-20240311210255067" loading="lazy"></figure>
<p>4次乘法+12次加法  减少至  4次乘法+8次加法</p>
<h4 id="3-二维卷积举例">3、二维卷积举例</h4>
<img src="http://cos.pansis.site/202403112106014.png/abc123" alt="image-20240311210601921" style="zoom:50%;" />
<img src="http://cos.pansis.site/202403112121098.png/abc123" alt="image-20240311212107989" style="zoom:50%;" />
<ul>
<li>可转化成矩阵乘法，代价是数据膨胀和冗余</li>
<li>可通过Winograd算法减少乘法次数，代价是会产生中间数据</li>
</ul>
<h2 id="三-减少数据搬运">三、减少数据搬运</h2>
<h4 id="1-方法">1、方法</h4>
<p>卷积数据流设计</p>
<h4 id="2-基本单元">2、基本单元</h4>
<img src="http://cos.pansis.site/202403121858743.png/abc123" alt="image-20240312185757278" style="zoom:50%;" />
<h4 id="3-数据流">3、数据流</h4>
<p>一个好的数据流设计：利用计算并行度、利用数据复用</p>
<p>三种形式：</p>
<ul>
<li>Output Stationary (OS)  输出不动</li>
<li>Weight Stationary (WS)  权值不动</li>
<li>Input Stationary (IS)  输入不动</li>
</ul>
<h4 id="4-output-stationary-os-输出不动">4、Output Stationary (OS)  输出不动</h4>
<p>以一维卷积为例</p>
<figure data-type="image" tabindex="6"><img src="http://cos.pansis.site/202403121903123.png/abc123" alt="image-20240312190304022" loading="lazy"></figure>
<ul>
<li>对于每个cycle，PE共享同一个weight ，相邻cycle之间weight不同</li>
<li>对于每个PE，将activation传递给右边的PE</li>
<li>对于每个activation，从最左边PE一直传递到最右边的PE</li>
</ul>
<h4 id="5-weight-stationary-ws">5、Weight Stationary (WS)</h4>
<figure data-type="image" tabindex="7"><img src="http://cos.pansis.site/202403121907869.png/abc123" alt="image-20240312190738780" loading="lazy"></figure>
<ul>
<li>对于每个cycle，PE共享同一个activation ，相邻cycle之间activation不同</li>
<li>对于每个PE，将psum传递给右边的PE</li>
<li>对于每个psum，从最左边PE一直传递到最右边的PE</li>
</ul>
<br />
                                            
                                </p>
                            </div>
                            <div class="post_footer">
                                
                                    <div class="meta">
                                        <div class="info"><span class="field tags"><i class="iconfont icon-tag-sm"></i>
                                                
                                                    <a href="https://github.pansis.site/tag/fxqznclqsjsy/" class="article-info">
                                                        飞行器智能处理器设计实验
                                                    </a>
                                                    
                                            </span>
                                        </div>
                                    </div>
                                    
                                        
                            </div>
                        </div>
                        
                            
                                <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
<div id="gitalk-container" style="padding-bottom: 20px;"></div>
<script>
    var pageId = (location.pathname).substring(1, 49) // Ensure uniqueness and length less than 50
    pageId = pageId.endsWith('/') ? pageId.slice(0, -1) : pageId // 以斜杠结尾则去除
    var gitalk = new Gitalk({
        clientID: '9d5eba33618472c44a07',
        clientSecret: '065a85ed04333ceebfc4f01d7ca1674175730339',
        repo: 'fzxl2003.github.io',
        owner: 'fzxl2003',
        admin: ['fzxl2003'],
        id: pageId,
        distractionFreeMode: false  // Facebook-like distraction free mode
    })
    gitalk.render('gitalk-container')
</script>
                                    
                                        
                                                    
                    </div>
                </div>
            </div>
    </div>
    <div class="footer">
    
    <div class="powered_by">
        <a href="https://codeberg.org/kytrun/gridea-theme-one" target="_blank">Theme One,</a>
        <a href="https://open.gridea.dev/" target="_blank">Powered by Gridea&#65281;</a>
    </div>
    
    
        <div class="footer_slogan">
            Powered by <a href="https://github.com/getgridea/gridea" target="_blank">Gridea</a>
        </div>
    
    <div id="back_to_top" class="back_to_top">
        <span>△</span>
    </div>
    
</div>

<script src="https://github.pansis.site/media/scripts/util.js"></script>
        <link rel="stylesheet" href="//unpkg.com/@highlightjs/cdn-assets@11.5.1/styles/default.min.css">
        <script src="//unpkg.com/@highlightjs/cdn-assets@11.5.1/highlight.min.js"></script>
        <script>hljs.highlightAll();</script>
</body>

</html>